from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from news.models import News


class NewsSerializer(serializers.ModelSerializer):

    def is_valid(self, raise_exception=False):
        try:
            super().is_valid(raise_exception=True)
        except Exception as e:
            assert isinstance(e, ValidationError)
            for k, v in e.detail.items():
                raise ValidationError({"err_msg": v[0]})

    class Meta:
        model = News
        fields = "__all__"